home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Misc / emu / Wzonka-Lad.lha / Wzonka-Lad / src / iconstartup.i < prev    next >
Text File  |  2003-12-26  |  4KB  |  127 lines

  1. ;
  2. ; Iconstartup.i
  3. ;
  4. ; include this to allow startup from icon.
  5. ; Just code the rest of your program as if you were writing for CLI.
  6. ;
  7. ; You should also add these lines to your code:
  8. ;
  9. ;    include "exec/exec_lib.i"
  10. ;    include    "exec/exec.i"
  11. ;    include    "libraries/dosextens.i
  12.  
  13. ;      include "exec/types.i"
  14. ;      include "exec/tasks.i"
  15. ;      include "dos/dosextens.i"
  16.  
  17. * All DOS processes have this STRUCTure
  18. * Create and DeviceProc returns pointer to the MsgPort in this STRUCTure
  19. * Process_addr = DeviceProc(..) - TC_SIZE
  20.  
  21. ;BPTR        MACRO        ; obsolete
  22. ;\1        EQU     SOFFSET
  23. ;SOFFSET    SET     SOFFSET+4
  24. ;        ENDM
  25.  
  26. ; STRUCTURE Process,0
  27. ;    STRUCT  pr_Task,TC_SIZE
  28. ;    STRUCT  pr_MsgPort,MP_SIZE    * This is BPTR address from DOS functions
  29. ;    WORD    pr_Pad        * Remaining variables on 4 byte boundaries
  30. ;    BPTR    pr_SegList        * Array of seg lists used by this process
  31. ;    LONG    pr_StackSize    * Size of process stack in bytes
  32. ;    APTR    pr_GlobVec        * Global vector for this process (BCPL)
  33. ;    LONG    pr_TaskNum        * CLI task number of zero if not a CLI
  34. ;    BPTR    pr_StackBase    * Ptr to high memory end of process stack
  35. ;    LONG    pr_Result2        * Value of secondary result from last call
  36. ;    BPTR    pr_CurrentDir    * Lock associated with current directory
  37. ;    BPTR    pr_CIS        * Current CLI Input Stream
  38. ;    BPTR    pr_COS        * Current CLI Output Stream
  39. ;    APTR    pr_ConsoleTask    * Console handler process for current window
  40. ;    APTR    pr_FileSystemTask    * File handler process for current drive
  41. ;    BPTR    pr_CLI        * pointer to CommandLineInterface
  42. ;    APTR    pr_ReturnAddr    * pointer to previous stack frame
  43. ;    APTR    pr_PktWait        * Function to be called when awaiting msg
  44. ;    APTR    pr_WindowPtr    * Window pointer for errors
  45. ;
  46. ;* following definitions are new with 2.0
  47. ;    BPTR    pr_HomeDir        * Home directory of executing program
  48. ;    LONG    pr_Flags        * flags telling dos about process
  49. ;    APTR    pr_ExitCode        * code to call on exit of program or NULL
  50. ;    LONG    pr_ExitData        * Passed as an argument to pr_ExitCode
  51. ;    APTR    pr_Arguments    * Arguments passed to the process at start
  52. ;    STRUCT  pr_LocalVars,MLH_SIZE * Local environment variables
  53. ;    APTR    pr_ShellPrivate    * for the use of the current shell
  54. ;    BPTR    pr_CES        * Error stream - if NULL, use pr_COS
  55. ;   LABEL   pr_SIZEOF        * Process
  56.  
  57. * All DOS processes have this STRUCTure
  58. * Create and DeviceProc returns pointer to the MsgPort in this STRUCTure
  59. * Process_addr = DeviceProc(..) - TC_SIZE
  60.  
  61. ; or similar code for your assembler...
  62. ;
  63. ; If your assembler won't assemble this, throw it away and buy
  64. ; the excellent HISOFT DEVPAC 3.0 from Hisoft Software.
  65.  
  66.     section start,code
  67.  
  68.     movem.l    d0/a0,-(sp)
  69.  
  70.     sub.l    a1,a1
  71.     move.l  ExecBase,a6
  72.     jsr    FindTask(a6)
  73.  
  74. ; Could use ThisTask(a6) here, but we won't. The general rule
  75. ; is that if there is a system function to read a structure, use
  76. ; that rather than peeking the structure directly. This gives
  77. ; Commodore greater freedom to change things in the future...
  78.  
  79.     move.l    d0,a4
  80.  
  81.     clr.b    cli_or_wb    ; cli.
  82.  
  83.     tst.l    pr_CLI(a4)    ; was it called from CLI?
  84.     bne.s   fromCLI        ; if so, skip out this bit...
  85.  
  86.     lea    pr_MsgPort(a4),a0
  87.     move.l  ExecBase,a6
  88.     jsr    WaitPort(A6)
  89.     lea    pr_MsgPort(a4),a0
  90.     jsr    GetMsg(A6)
  91.     move.l    d0,returnMsg
  92.  
  93.     move.b    #1,cli_or_wb    ; wb.
  94.  
  95. fromCLI
  96.     movem.l    (sp)+,d0/a0
  97.  
  98. go_program
  99.  
  100.  
  101.     bsr.w    gb_emu              ; Calls your code..
  102.  
  103. ; If your code does not allow exit, the following lines are
  104. ; not required
  105.  
  106.     move.l    d0,-(sp)
  107.  
  108.     tst.l    returnMsg        ; Is there a message?
  109.     beq.s    exitToDOS        ; if not, skip...
  110.  
  111.     move.l    ExecBase,a6
  112.         jsr    Forbid(a6)          ; note! No Permit needed!
  113.  
  114.     move.l    returnMsg(pc),a1
  115.     jsr    ReplyMsg(a6)
  116.  
  117. exitToDOS
  118.     move.l    (sp)+,d0        ; exit code
  119.     rts
  120.  
  121. ; These next lines are required whether you want to exit or not!
  122.  
  123.  
  124. returnMsg:    dc.l    0
  125.         cnop    0,4
  126.         even
  127.